
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "CBLEDataMsg.h"
#import "ZBLEDataModel.h"
#import "ZBLEhandleDataModel.h"

typedef NS_ENUM(NSInteger,DevWiFiType) {
    DevWiFiType360K = 0,
    DevWiFiType362K = 2
};

typedef NS_ENUM(NSInteger,DevBrandType) {
    DevBrandTypeRenon = 1,
    DevBrandTypeKowint = 2,
    DevBrandTypeZRGP = 3
};

@class CDataPheralInfo;
//蓝牙管理器中心协议

@protocol CDataPheralInfoDelegate <NSObject>

@optional
- (void)wristCmdAck:(nullable CDataPheralInfo *) manager
            ackData:(MsgDataWristAck *_Nullable)accData;

- (void)reviceAck:(nullable CDataPheralInfo *) manager
            ackData:(ZBLEDataModel *_Nullable)model;

- (void)wristAck:(nullable CDataPheralInfo *) manager
            ackData:(ZBLEhandleDataModel *_Nullable)model;

@end

//1.外部蓝牙设备的基本数据类型
@interface CDataPheralInfo : NSObject<NSCoding,NSSecureCoding>
@property (nonatomic, weak, nullable) id <CDataPheralInfoDelegate> delegate;
@property (nonatomic, strong) CBPeripheral  * _Nullable peripheral;
@property (nonatomic, strong) NSDictionary  * _Nullable advData;
@property (nonatomic, strong) NSNumber      * _Nullable RSSI;
@property (nonatomic, assign) NSInteger     maxPacketLength;//每一包的最大长度
@property (nonatomic, copy)   NSString      * _Nullable adverMacAddr;//mac地址
@property (nonatomic, copy)   NSString      *_Nullable deviceId;//设备id
@property (nonatomic, assign)   NSInteger   productId;//产品id
@property (nonatomic, copy)   NSString      *_Nullable deviceType;//设备类型 HE_BAT,HE_ALLINONE
@property (nonatomic, assign) DevBrandType brandType;//品牌
@property (nonatomic, copy)   NSString      *_Nullable productName;//产品名  Ebrick
@property (nonatomic, assign) BOOL          hasMaster;//是否带主控
@property (nonatomic, assign,getter=isHighVoltage) BOOL    highVoltage;//是否高压
@property (nonatomic, assign) DevWiFiType wifiType;   //wifi模组类型 360不支持modbus
@property (nonatomic, copy) NSString        *_Nullable devName;//匹配设备的设备id
@property (nonatomic, assign,readonly)BOOL  bIsInOTA;
@property (nonatomic, copy)    NSString     * _Nullable strBootVer;
@property (nonatomic, strong) ZBLEDataModel * _Nullable  model1;
@property (nonatomic, strong) ZBLEDataModel * _Nullable model2;
@property (nonatomic, assign) BOOL isHandleData;

@property (nonatomic, assign) NSTimeInterval connectTime;//设备连接的时间

+(instancetype _Nullable )dataPheral:(CBPeripheral*_Nullable)pheral advData:(NSDictionary *_Nullable)advData RSSI:(NSNumber *_Nullable)RSSI;
-(BOOL)isSamePheral:(CBPeripheral*_Nullable)pheral;
-(void)startFindSrv:(CBPeripheral*_Nullable)pheral;
-(void)disConnect:(CBPeripheral*_Nullable)pheral;

-(void)writeCmdAckMsg:(NSData*_Nullable)cmdData;
-(void)readCmdAckMsg:(NSData*_Nullable)cmdData;
-(void)writeOTACmd:(NSData*_Nullable)otaCmdData bInOTA:(BOOL)bInOTA;
-(void)writeOTAData:(NSData*_Nullable)otaData;

-(NSString*_Nullable)fmtBootVer;
-(BOOL)isSamePheralWithMacAddr:(NSString*_Nullable)devMac;
-(BOOL)isSamePheralWithUUID:(NSString*_Nullable)uuidStr;
-(BOOL)isSamePeralWithName:(NSString*_Nullable)perName;

- (BOOL)wristSsidMsg:(NSData* _Nullable)data;
- (BOOL)wristPassMsg:(NSData* _Nullable)data;

@end



//2.外部蓝牙设备的数据管理
@interface CDataPheralMnger : NSObject
+(instancetype _Nullable )dataMnger;
-(NSInteger)totalNums;
-(CDataPheralInfo*_Nullable)dataWithIndex:(NSInteger)nIdx;

-(void)removeAll;
-(BOOL)addPheral:(CDataPheralInfo*_Nullable)data;
-(BOOL)addPheral:(CBPeripheral*_Nullable)pheral advData:(NSDictionary *_Nullable)advData RSSI:(NSNumber *_Nullable)RSSI;

//保存连接过的蓝牙
-(void)saveBleDevice:(CDataPheralInfo*_Nullable)device;
//读取连接过的蓝牙
-(NSArray*_Nullable)readBleDevice;
//删除本地设备
-(void)deleteLocalDevice:(CDataPheralInfo*_Nullable)device;
//删除全部本地设备
-(BOOL)deleteAllLocalDevices;
@end
